﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hsinchu.BLL;
using Hsinchu.Model;

public partial class Admin_ProductMgr_AddProduct : System.Web.UI.Page
{
    CategoryMgr dllCategoryMgr = new CategoryMgr();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitLoad();
        }
    }

    void InitLoad()
    {
        BindCategoryCombox();
    }


    /// <summary>
    /// 绑定类别dropdownList
    /// </summary>
    void BindCategoryCombox()
    {
        Dictionary<string, string> category = dllCategoryMgr.GetCategoryByParentCategoryId(0);
        foreach (KeyValuePair<string, string> item in category)
        {
            ListItem _li = new ListItem();
            _li.Text = item.Key;
            _li.Value = item.Value;
            this.drpCategory.Items.Add(_li);
        }
    }


    /// <summary>
    /// 添加新产品
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        MItem item = new MItem();
        item.Name = this.txtItemName.Text;
        item.CategoryId =Convert.ToInt32(this.drpCategory.SelectedValue);
        item.TableName = this.txtTableName.Text;
        ItemMgr dllItemMgr = new ItemMgr();
        dllItemMgr.AddItem(item);
    }
}
